home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 25.1 KB | 949 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawPart.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Henri Lamiraux
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRAME_H
- #include "DrawFrame.h"
- #endif
-
- #ifndef SHAPES_H
- #include "Shapes.h"
- #endif
-
- #ifndef DRAWSELECTION_H
- #include "DrawSelection.h"
- #endif
-
- #ifndef TOOLFRAME_H
- #include "ToolFrame.h"
- #endif
-
- #ifndef TOOLFACET_H
- #include "ToolFacet.h"
- #endif
-
- #ifndef PALETTEFRAME_H
- #include "PaletteFrame.h"
- #endif
-
- #ifndef PALETTEFACET_H
- #include "PaletteFacet.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- // ----- OPF Foundation Includes -----
-
- #ifndef BCSTOREU_H
- #include <BCStoreU.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _ARBITRAT_
- #include <Arbitrat.h>
- #endif
-
- #ifndef _DRAFT_
- #include <Draft.h>
- #endif
-
- #ifndef _DISPTCH_
- #include <Disptch.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _FRAME_
- #include <Frame.h>
- #endif
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _STORAGEU_
- #include <StorageU.h>
- #endif
-
- #ifndef _SUVIEW_
- #include <SUView.h>
- #endif
-
- #ifndef _SUCURSOR_
- #include <SUCursor.h>
- #endif
-
- #ifndef _XMPSESSN_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _INFO_
- #include <Info.h>
- #endif
-
- #ifndef _MENUBAR_
- #include <MenuBar.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _WINSTAT_
- #include <WinStat.h>
- #endif
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- #ifndef _SEMTINTF_
- #include <SemtIntf.h>
- #endif
-
- #ifndef _NAMRSLVR_
- #include <NamRslvr.h>
- #endif
-
- #ifndef _STDPROPS_
- #include <StdProps.h>
- #endif
-
- #ifndef _STDTYPES_
- #include <StdTypes.h>
- #endif
-
- #ifndef _DRAGDROP_
- #include <DragDrop.h>
- #endif
-
- #ifndef _CMDDEFS_
- #include <CmdDefs.h>
- #endif
-
- #ifndef _LINKSRC_
- #include <LinkSrc.h>
- #endif
-
- #ifndef _LINK_
- #include <Link.h>
- #endif
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #ifndef __EVENTS__
- #include <Events.h> // GetMouse, StillDown.
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __PICKER__
- #include <Picker.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h> // HiWord etc.
- #endif
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef __STDLIB__
- #include <StdLib.h> // Abs
- #endif
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h> // See MoveTransformBy
- #endif
-
- #pragma segment drawpart
-
- //=========================================================================
- // •• class CDrawPart
- //=========================================================================
-
- //------------------------------------------------------------------------------
- // • CDrawPart::CDrawPart
- //------------------------------------------------------------------------------
-
- CDrawPart::CDrawPart()
- {
- fPenSizeMenu = NULL;
- fArrangeMenu = NULL;
- fWindowMenu = NULL;
-
- fShapeList = NULL;
- fCurrentPenSize = ff(1);
- fFillFrame = kFrameFill;
-
- fNbEmbedded = 0;
-
- fPaletteWindow = NULL;
- fToolsWindow = NULL;
- fTool = kRectangle;
-
- fDrawSelection = NULL;
-
- fFillColor = FW_kRGBWhite;
- fPenColor = FW_kRGBBlack;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::~CDrawPart
- //------------------------------------------------------------------------------
-
- CDrawPart::~CDrawPart()
- {
- if (fPenSizeMenu)
- ::DisposeMenu(fPenSizeMenu);
-
- if (fArrangeMenu)
- ::DisposeMenu(fArrangeMenu);
-
- if (fWindowMenu)
- ::DisposeMenu(fWindowMenu);
-
- delete fShapeList;
- fShapeList = NULL;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::Initialize
- //------------------------------------------------------------------------------
-
- void CDrawPart::Initialize()
- {
- FW_CEmbeddingPart::Initialize();
-
- fShapeList = new BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>;
-
- fArrangeMenu = ::NewMenu(kArrangeMenu,"\pArrange");
- fPenSizeMenu = ::NewMenu(kPenSizeMenu,"\pSize");
- fWindowMenu = ::NewMenu(kWindowMenu,"\pWindows");
-
- ::AppendMenu(fPenSizeMenu,"\p1 Pixel");
- ::AppendMenu(fPenSizeMenu,"\p2 Pixels");
- ::AppendMenu(fPenSizeMenu,"\p3 Pixels");
- ::AppendMenu(fPenSizeMenu,"\p4 Pixels");
- ::AppendMenu(fPenSizeMenu,"\p5 Pixels");
-
- ::AppendMenu(fArrangeMenu,"\pMove Forward /F");
- ::AppendMenu(fArrangeMenu,"\pMove To Front");
- ::AppendMenu(fArrangeMenu,"\pMove Backward /B");
- ::AppendMenu(fArrangeMenu,"\pMove To Back");
- ::AppendMenu(fArrangeMenu,"\p-");
- ::AppendMenu(fArrangeMenu,"\pFreeze");
- ::AppendMenu(fArrangeMenu,"\pDefrost");
-
- ::AppendMenu(fWindowMenu,"\pabc/P"); // will be changed in AdjustMenus
- ::AppendMenu(fWindowMenu,"\pabc/T"); // will be changed in AdjustMenus
-
- XMPMenuBar *menuBar = GetMenuBar();
-
- menuBar->AddMenuLast(kArrangeMenu, fArrangeMenu, this);
- menuBar->AddMenuLast(kPenSizeMenu, fPenSizeMenu, this);
- menuBar->AddMenuLast(kWindowMenu, fWindowMenu, this);
-
- menuBar->RegisterCommand(cMoveForward, kArrangeMenu, 1);
- menuBar->RegisterCommand(cMoveToFront, kArrangeMenu, 2);
- menuBar->RegisterCommand(cMoveBackward, kArrangeMenu, 3);
- menuBar->RegisterCommand(cMoveToBack, kArrangeMenu, 4);
- menuBar->RegisterCommand(cFreeze, kArrangeMenu, 6);
- menuBar->RegisterCommand(cDefrost, kArrangeMenu, 7);
-
- menuBar->RegisterCommand(cPen1, kPenSizeMenu, 1);
- menuBar->RegisterCommand(cPen2, kPenSizeMenu, 2);
- menuBar->RegisterCommand(cPen3, kPenSizeMenu, 3);
- menuBar->RegisterCommand(cPen4, kPenSizeMenu, 4);
- menuBar->RegisterCommand(cPen5, kPenSizeMenu, 5);
-
- menuBar->RegisterCommand(cHideShowPalette, kWindowMenu, 1);
- menuBar->RegisterCommand(cHideShowTools, kWindowMenu, 2);
-
- // ----- Tokenize -----
- fToolPresentation = GetSession()->Tokenize(kToolPresentation);
- fPalettePresentation = GetSession()->Tokenize(kPalettePresentation);
- fMainPresentation = GetSession()->Tokenize(kMainPresentation);
-
- // ----- Create tool window object
- FW_CRect toolRect(ff(100), ff(100), ff(100+kToolsWindowWidth), ff(100 + kToolsWindowHeight));
- fToolsWindow = new FW_CFloatingWindow;
- fToolsWindow->InitFloatingWindow(this, fToolPresentation, toolRect);
-
- // ----- Create palette window object
- FW_CRect paletteRect(ff(100), ff(100), ff(100+kPaletteWindowWidth), ff(100+kPaletteWindowHeight));
- fPaletteWindow = new FW_CFloatingWindow;
- fPaletteWindow->InitFloatingWindow(this, fPalettePresentation, paletteRect);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::AddProperties
- //------------------------------------------------------------------------------
-
- void CDrawPart::AddProperties(XMPStorageUnit* storageUnit)
- {
- storageUnit->AddProperty(kContentAnnotationProp)->AddValue(kContentAnnotationValue);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::InternalizeContent
- //------------------------------------------------------------------------------
-
- void CDrawPart::InternalizeContent(XMPStorageUnit* storageUnit)
- {
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
-
- // ----- Read number of shapes -----
- unsigned long count;
- storageUnit->GetValue(sizeof(count), (XMPValue)&count);
-
- // ----- Read top left offset -----
- XMPCoordinate xTopLeft, yTopLeft;
- storageUnit->GetValue(sizeof(xTopLeft), (XMPValue)&xTopLeft);
- storageUnit->GetValue(sizeof(yTopLeft), (XMPValue)&yTopLeft);
-
- for (unsigned long i = 0; i<count; i++)
- {
- unsigned short shapeType;
- storageUnit->GetValue(sizeof(unsigned short), (XMPValue)&shapeType);
- CBaseShape* theShape = NewShape(shapeType);
- if (theShape)
- {
- theShape->Unflatten(this, storageUnit);
- fShapeList->Append(theShape);
-
- if (theShape->IsSelected())
- fDrawSelection->AddToSelection(theShape, TRUE);
-
- if (xTopLeft != 0 || yTopLeft != 0)
- {
- theShape->OffsetShape(xTopLeft, yTopLeft);
- }
- }
- }
-
- // ----- Read general information -----
- if (storageUnit->Exists(kContentAnnotationProp, (XMPValueType)kContentAnnotationValue, 0))
- {
- storageUnit->Focus(kContentAnnotationProp, kXMPPosUndefined, kContentAnnotationValue, (XMPValueIndex)0, kXMPPosUndefined);
- storageUnit->GetValue(sizeof(unsigned short), (XMPValue)&fTool);
- storageUnit->GetValue(sizeof(XMPCoordinate), (XMPValue)&fCurrentPenSize);
- storageUnit->GetValue(sizeof(unsigned short), (XMPValue)&fFillFrame);
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::ExternalizeContent
- //------------------------------------------------------------------------------
-
- void CDrawPart::ExternalizeContent(XMPStorageUnit* storageUnit)
- {
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
- storageUnit->Remove();
- storageUnit->AddValue(this->GetContentPropertyValueType());
-
- // ----- Write number of shapes -----
- unsigned long count = fShapeList->Length();
- storageUnit->SetValue(sizeof(count), (XMPValue)&count);
-
- // ----- Write top left offset -----
- XMPCoordinate coordinate = 0;
- storageUnit->SetValue(sizeof(coordinate), (XMPValue)&coordinate);
- storageUnit->SetValue(sizeof(coordinate), (XMPValue)&coordinate);
-
- // ----- Write shapes -----
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fShapeList);
- while (!ite.IsDone())
- {
- (*ite.CurrentItem())->Flatten(storageUnit);
- ite.Next();
- }
-
- // ----- Write general information -----
- storageUnit->Focus(kContentAnnotationProp, kXMPPosUndefined, kContentAnnotationValue, (XMPValueIndex)0, kXMPPosUndefined);
- storageUnit->SetValue(sizeof(unsigned short), (XMPValue)&fTool);
- storageUnit->SetValue(sizeof(XMPCoordinate), (XMPValue)&fCurrentPenSize);
- storageUnit->SetValue(sizeof(unsigned short), (XMPValue)&fFillFrame);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::NewShape
- //------------------------------------------------------------------------------
-
- CBaseShape* CDrawPart::NewShape(unsigned short shapeType)
- {
- CBaseShape *theShape = NULL;
-
- switch (shapeType) {
- case kLineShape:
- theShape = new CLineShape();
- break;
- case kRectShape:
- theShape = new CRectShape();
- break;
- case kOvalShape:
- theShape = new COvalShape();
- break;
- case kRRectShape:
- theShape = new CRoundRectShape();
- break;
- case kProxyShape:
- theShape = new CProxyShape();
- break;
- }
-
- return theShape;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::Release
- //------------------------------------------------------------------------------
-
- void CDrawPart::Release()
- {
- if (fShapeList && this->GetRefCount() == 1)
- {
- CBaseShape* shape;
- while (!fShapeList->IsEmpty())
- {
- shape = fShapeList->First();
- fShapeList->Remove(fShapeList->Location(shape));
- delete shape;
- }
- }
-
- FW_CEmbeddingPart::Release();
- }
-
-
- //------------------------------------------------------------------------------
- // • CDrawPart::NewSelection
- //------------------------------------------------------------------------------
- // We keep a reference to the selection around to avoid
- // typecast. fDrawSelection will be deleted by FW_CPart
-
- FW_CSelection* CDrawPart::NewSelection()
- {
- fDrawSelection = new CDrawSelection;
- fDrawSelection->InitDrawSelection(this);
- return fDrawSelection;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::DeleteShape
- //------------------------------------------------------------------------------
- void CDrawPart::DeleteShape(CBaseShape* shape)
- {
- fShapeList->Remove(fShapeList->Location(shape));
- shape->Removed();
- delete shape;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::AddShape
- //------------------------------------------------------------------------------
- void CDrawPart::AddShape(CBaseShape* shape)
- {
- fShapeList->Insert(shape, 0);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::AddShapeAfter
- //------------------------------------------------------------------------------
- void CDrawPart::AddShapeAfter(CBaseShape* after, CBaseShape* shape)
- {
- fShapeList->Append(shape, fShapeList->Location(after));
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::GetContentPropertyValueType
- //------------------------------------------------------------------------------
- XMPValueType CDrawPart::GetContentPropertyValueType() const
- {
- return kDrawKind;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::DoMenuEvent
- //------------------------------------------------------------------------------
- FW_Boolean CDrawPart::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID commandID)
- {
- FW_Boolean result = TRUE;
-
- if (cPen1 <= commandID && commandID <= cPen5)
- {
- XMPCoordinate penSize = ff(commandID - cPen1 + 1);
- if (!fDrawSelection->IsEmpty())
- fDrawSelection->ChangeSelectionPenSize(penSize);
- else
- fCurrentPenSize = penSize;
- }
- else
- {
- switch (commandID)
- {
- case cHideShowPalette:
- fPaletteWindow->HideShowFloating();
- break;
- case cHideShowTools:
- fToolsWindow->HideShowFloating();
- break;
- case cMoveForward:
- MoveForward();
- this->Changed();
- break;
- case cMoveToFront:
- MoveToFront();
- this->Changed();
- break;
- case cMoveBackward:
- MoveBackward();
- this->Changed();
- break;
- case cMoveToBack:
- MoveToBack();
- this->Changed();
- break;
- case cFreeze:
- fDrawSelection->SetFrozen(TRUE);
- this->Changed();
- break;
- case cDefrost:
- fDrawSelection->SetFrozen(FALSE);
- this->Changed();
- break;
- default:
- result = FW_CEmbeddingPart::DoMenuEvent(menuBar, commandID);
- }
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::SetTool
- //------------------------------------------------------------------------------
- void CDrawPart::SetTool(unsigned short newTool)
- {
- if (fTool != newTool)
- {
- if (fTool == kSelectTool && !fDrawSelection->IsEmpty())
- {
- fDrawSelection->CloseSelection();
- }
-
- CheckTool(fTool, newTool);
- fTool = newTool;
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::SetFillFrame
- //------------------------------------------------------------------------------
- void CDrawPart::SetFillFrame(unsigned short fillFrame)
- {
- if (fFillFrame != fillFrame)
- {
- if (!fDrawSelection->IsEmpty())
- fDrawSelection->ChangeSelectionFillFrame(fillFrame);
-
- unsigned short oldFillFrame = fFillFrame;
- fFillFrame = fillFrame;
- CheckFillFrame(oldFillFrame, fFillFrame);
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::NewFrame
- //------------------------------------------------------------------------------
- FW_CFrame* CDrawPart::NewFrame(XMPFrame* xmpFrame, XMPTypeToken presentation)
- {
- if (presentation == fPalettePresentation)
- {
- CPaletteFrame *frame = new CPaletteFrame();
- frame->InitPaletteFrame(xmpFrame, this);
- return frame;
- }
- else if (presentation == fToolPresentation)
- {
- CToolFrame *frame = new CToolFrame();
- frame->InitToolFrame(xmpFrame, this);
- return frame;
- }
-
- CDrawFrame *frame = new CDrawFrame();
- frame->IDrawFrame(xmpFrame, this);
- return frame;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::DoAdjustMenus
- //------------------------------------------------------------------------------
-
- void CDrawPart::DoAdjustMenus(XMPMenuBar* menuBar)
- {
- FW_CEmbeddingPart::DoAdjustMenus(menuBar);
-
- XMPCommandID command;
-
-
- // ----- PenSize Menu -----
- XMPCoordinate penSize = fCurrentPenSize;
- if (fDrawSelection->Count() >= 1)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawSelection->GetSelectionCollection());
- CBaseShape* shape = *ite.CurrentItem();
- penSize = shape->GetPenSize();
- }
- command = FixedToInt(penSize) + cPen1 - 1;
-
- for (XMPCommandID p = cPen1; p <= cPen5; p++)
- menuBar->CheckCommand(p, p == command);
-
- FW_Boolean hasSelection = fDrawSelection->Count()>0;
-
- // ----- Edit Menu -----
- menuBar->EnableCommand(kXMPCommandSelectAll, fShapeList->Length()>0);
- menuBar->EnableCommand(kXMPCommandPaste, HasPropertyOnClipboard(kXMPPropContents, NULL)); // we don't care about the type
-
- // ----- Arrange Menu -----
- menuBar->EnableCommand(cMoveForward, hasSelection);
- menuBar->EnableCommand(cMoveToFront, hasSelection);
- menuBar->EnableCommand(cMoveBackward, hasSelection);
- menuBar->EnableCommand(cMoveToBack, hasSelection);
- menuBar->EnableCommand(cFreeze, fDrawSelection->HasNotFrozen());
- menuBar->EnableCommand(cDefrost, fDrawSelection->HasFrozen());
-
- // ----- Window Menu
- if (fToolsWindow->IsShown())
- menuBar->SetItemString(cHideShowTools, "\pHide Tools");
- else
- menuBar->SetItemString(cHideShowTools, "\pShow Tools");
-
- if (fPaletteWindow->IsShown())
- menuBar->SetItemString(cHideShowPalette, "\pHide Palette");
- else
- menuBar->SetItemString(cHideShowPalette, "\pShow Palette");
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::NewProxyShape
- //------------------------------------------------------------------------------
-
- CProxyShape* CDrawPart::NewProxyShape(XMPPart* xmpPart, const FW_CRect& shapeRect, FW_Boolean invalidate)
- {
- // ----- decide on a position -----
- fNbEmbedded++;
- short offset = 40 + fNbEmbedded*20;
- FW_CPoint temp(ff(offset), ff(offset));
- XMPTransform* externalXForm = ::NewXMPTransform(temp);
-
- FW_CRect tempRect = shapeRect;
- XMPShape *frameShape = ::NewXMPShape(tempRect);
-
- // ----- Create the shape
- tempRect.Offset(ff(offset), ff(offset));
- CProxyShape* theShape = new CProxyShape(tempRect);
-
- // ----- Add the shape to the list of shape -----
- AddShape(theShape);
-
- // ----- Create the proxyRun -----
- CDrawProxyRun* proxyRun = (CDrawProxyRun*)NewProxyRun();
-
- // ----- Set the proxyRun of the shape and the shape of the proxyRun -----
- theShape->SetProxyRun(proxyRun);
- proxyRun->SetShape(theShape);
-
- // ----- Embed the part -----
- EmbedPart(xmpPart, proxyRun, fMainPresentation,
- GetSession()->Tokenize(kXMPViewAsFrame), kNoPresentation,
- externalXForm, frameShape, invalidate);
-
- // ----- Select the selection tool -----
- SetTool(kSelectTool);
-
- return theShape;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::NewProxyRun
- //------------------------------------------------------------------------------
-
- FW_CProxyRun* CDrawPart::NewProxyRun()
- {
- CDrawProxyRun *proxyRun = new CDrawProxyRun();
- proxyRun->InitDrawProxyRun(this);
-
- return proxyRun;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::CheckTool
- //------------------------------------------------------------------------------
-
- void CDrawPart::CheckTool(unsigned short oldTool, unsigned short newTool)
- {
- BC_TCollectionActiveIterator<FW_CFrame*> ite(*this->GetDisplayFrameList());
- FW_CFrame *frame;
- while (!ite.IsDone())
- {
- frame = *ite.CurrentItem();
- if (frame->GetPresentation() == fToolPresentation)
- {
- FW_CFrameFacetIterator ite2(frame);
- while (!ite2.IsDone())
- {
- ((CToolFacet*)ite2.CurrentItem())->CheckTool(oldTool, newTool);
- ite2.Next();
- }
- }
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::CheckFillFrame
- //------------------------------------------------------------------------------
-
- void CDrawPart::CheckFillFrame(unsigned short oldFillFrame, unsigned short newFillFrame)
- {
- BC_TCollectionActiveIterator<FW_CFrame*> ite(*this->GetDisplayFrameList());
- FW_CFrame *frame;
- while (!ite.IsDone())
- {
- frame = *ite.CurrentItem();
- if (frame->GetPresentation() == fToolPresentation)
- {
- FW_CFrameFacetIterator ite2(frame);
- while (!ite2.IsDone())
- {
- ((CToolFacet*)ite2.CurrentItem())->CheckFillFrame(oldFillFrame, newFillFrame);
- ite2.Next();
- }
- }
- ite.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::MoveForward
- //------------------------------------------------------------------------------
-
- void CDrawPart::MoveForward()
- {
- FW_Boolean didIt = FALSE;
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawSelection->GetSelectionCollection());
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- BC_Index curIndex = fShapeList->Location(shape);
- if (curIndex >= 1)
- {
- CBaseShape* previous = (*fShapeList)[curIndex-1];
- fShapeList->Remove(curIndex);
- fShapeList->Insert(shape, curIndex-1);
- previous->MovedBefore(shape);
- didIt = TRUE;
- }
- ite.Next();
- }
-
- if (didIt)
- {
- ClipEmbeddedFrames(fMainPresentation);
- InvalidateAllFrames(fMainPresentation, NULL, fDrawSelection->GetUpdateShape());
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::MoveBackward
- //------------------------------------------------------------------------------
-
- void CDrawPart::MoveBackward()
- {
- FW_Boolean didIt = FALSE;
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawSelection->GetSelectionCollection());
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- BC_Index curIndex = fShapeList->Location(shape);
- if (curIndex < fShapeList->Length() - 1)
- {
- CBaseShape* next = (*fShapeList)[curIndex+1];
- fShapeList->Remove(curIndex);
- fShapeList->Append(shape, curIndex); // and not curIndex+1 because we removed curIndex
- next->MovedAfter(shape);
- didIt = TRUE;
- }
- ite.Next();
- }
-
- if (didIt)
- {
- ClipEmbeddedFrames(fMainPresentation);
- InvalidateAllFrames(fMainPresentation, NULL, fDrawSelection->GetUpdateShape());
- }
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::MoveToFront
- //------------------------------------------------------------------------------
-
- void CDrawPart::MoveToFront()
- {
- BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>* extract = ExtractSelection();
-
- FW_TCollectionActiveIterator<CBaseShape*> ite(*extract, TRUE); // Iterate backwards
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- fShapeList->Insert(shape, 0);
- shape->MovedFirst();
- ite.Previous();
- }
- delete extract;
-
- ClipEmbeddedFrames(fMainPresentation);
- InvalidateAllFrames(fMainPresentation, NULL, fDrawSelection->GetUpdateShape());
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::MoveToBack
- //------------------------------------------------------------------------------
-
- void CDrawPart::MoveToBack()
- {
- BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>* extract = ExtractSelection();
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*extract);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- fShapeList->Append(shape);
- shape->MovedLast();
- ite.Next();
- }
- delete extract;
-
- ClipEmbeddedFrames(fMainPresentation);
- InvalidateAllFrames(fMainPresentation, NULL, fDrawSelection->GetUpdateShape());
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::ExtractSelection
- //------------------------------------------------------------------------------
-
- BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>* CDrawPart::ExtractSelection()
- {
- BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>* extract = new BC_TUnboundedCollection<CBaseShape*, BC_CUnmanaged>;
-
- // ----- Create the extract list -----
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fShapeList);
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- if (shape->IsSelected())
- extract->Append(shape);
- ite.Next();
- }
-
- // ----- Remove then from the shape list -----
- BC_TCollectionActiveIterator<CBaseShape*> ite2(*extract);
- while (!ite2.IsDone())
- {
- fShapeList->Remove(fShapeList->Location(*ite2.CurrentItem()));
- ite2.Next();
- }
-
- return extract;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::GetDefaultPresentation
- //------------------------------------------------------------------------------
-
- XMPTypeToken CDrawPart::GetDefaultPresentation() const
- {
- return fMainPresentation;
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::SetFillColor
- //------------------------------------------------------------------------------
-
- void CDrawPart::SetFillColor(const FW_CColor& color)
- {
- if (fDrawSelection->IsEmpty())
- {
- fFillColor = color;
- FW_CPartFacetIterator ite(this, GetToolPresentation());
- while (!ite.IsDone())
- {
- ((CToolFacet*)ite.CurrentItem())->UpdateColors();
- ite.Next();
- }
- }
- else
- fDrawSelection->ChangeSelectionFillColor(color);
- }
-
- //------------------------------------------------------------------------------
- // • CDrawPart::SetPenColor
- //------------------------------------------------------------------------------
-
- void CDrawPart::SetPenColor(const FW_CColor& color)
- {
- if (fDrawSelection->IsEmpty())
- {
- fPenColor = color;
- FW_CPartFacetIterator ite(this, GetToolPresentation());
- while (!ite.IsDone())
- {
- ((CToolFacet*)ite.CurrentItem())->UpdateColors();
- ite.Next();
- }
- }
- else
- fDrawSelection->ChangeSelectionPenColor(color);
- }
-